package domain;

import astar.AStar;
import domain.Game.direction;
import domain.exceptions.CannotMoveThereException;
import java.util.LinkedList;
import java.util.Vector;

/**
 *
 * @author ika
 */
public class AgentSmart extends Agent{
    
    private LinkedList<direction> _actionsPath;
    
    public AgentSmart(String name,Game.direction lastDirection){
        super(name, lastDirection);
        this._actionsPath = think();
    }
    
    @Override
    public void die() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void play(){
        if(this._actionsPath.isEmpty()){
            System.err.println("Actions Path is Empty");
        }
        Game.direction dir = this._actionsPath.poll();
        try {
            move(dir);
        } catch (CannotMoveThereException ex) {
            System.err.println(ex.getMessage());
        }
    }

    private boolean shouldStop() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    private LinkedList<direction> think() {
       AStar aStar = new AStar(this);
       Board board = Game._board;
       Vector<Agent> agentsClone = (Vector<Agent>)Game.getAgents().clone();
       Vector<Flag> flagsClone = (Vector<Flag>)Game._board.getFlags().clone();
       return aStar.runAStarSearch(board, agentsClone, flagsClone);
    }
}